package org.example.myleet.p1189;

public class Solution {
    public int maxNumberOfBalloons(String text) {
        char[] charArr = text.toCharArray();
        //代表b-a-l-o-n的数目统计
        int[] charCount = new int[5];
        for (char c : charArr) {
            switch (c) {
                case 'b': {
                    ++charCount[0];
                    break;
                }
                case 'a': {
                    ++charCount[1];
                    break;
                }
                case 'l': {
                    ++charCount[2];
                    break;
                }
                case 'o': {
                    ++charCount[3];
                    break;
                }
                case 'n': {
                    ++charCount[4];
                    break;
                }
            }
        }
        int[] possibleBalloonCount = new int[5];
        possibleBalloonCount[0] = charCount[0];
        possibleBalloonCount[1] = charCount[1];
        possibleBalloonCount[2] = charCount[2] / 2;
        possibleBalloonCount[3] = charCount[3] / 2;
        possibleBalloonCount[4] = charCount[4];
        int maxBalloonCount = Integer.MAX_VALUE;
        for (int c : possibleBalloonCount) {
            maxBalloonCount = Math.min(maxBalloonCount, c);
        }
        return maxBalloonCount;
    }
}
